package cn.cdiothree.controller;


import cn.cdiothree.dataobject.ProductCollect;
import cn.cdiothree.service.ProductCollectService;
import cn.cdiothree.vo.ProductCollectVo;
import cn.cdiothree.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品收藏控制层
 * @author cumthing
 */
@RestController
@RequestMapping("/product-info")
public class ProductCollectController {
    @Autowired
    ProductCollectService productCollectService;

    /**
     * 添加收藏
     * @param productId
     * @param userId
     * @return
     */
    @GetMapping("/add/collect")
    public ResultVo addCollect(@RequestParam("productId") Integer productId,
                               @RequestParam("userId") Integer userId){
        ResultVo productCollect=productCollectService.addOrCancelCollect(productId,userId);
        return ResultVo.success(productCollect);
    }

    /**
     * 查看收藏状态
     * @param productId
     * @param userId
     * @return
     */
    @GetMapping("/collect")
    public ResultVo collect(@RequestParam("productId")Integer productId,
                            @RequestParam("userId") Integer userId){
        ProductCollect productCollect = productCollectService.selectByProductIdAndUserId(productId,userId);
        return ResultVo.success(productCollect);
    }

    @GetMapping("/list")
    public List<ProductCollectVo> list(Integer userId){
        List<ProductCollectVo> productCollectVoList = productCollectService.list(userId);
        return productCollectVoList;
    }
}
